package cz.czu.pef.DataModelling.tests.utils;

import java.util.logging.Logger;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cz.czu.pef.DataModelling.utils.Constants;

public class SpringLoaderHelper
{
  private static ApplicationContext applicationContext = null;
  public static final Logger logger = Logger.getLogger(SpringLoaderHelper.class.getName());

  public static ApplicationContext getApplicationContext()
  {
    try
    {
      logger.finest("getApplicationContext():: Entry");
      if (applicationContext != null)
        return applicationContext;
      synchronized (SpringLoaderHelper.class)
      {
        if (applicationContext == null)
        {
          String stackTrace = (new RuntimeException()).fillInStackTrace().toString();
          logger.info("getApplicationContext():: Loading context" + stackTrace);
          applicationContext = new ClassPathXmlApplicationContext(Constants.springTestingClasspathConfig);
        }
      }
      return applicationContext;
    }
    finally
    {
      logger.finest("getApplicationContext():: Exit");
    }
  }
}
